import {useMyRouter} from "../store/moduls/usemyroute";

export const createRouterGuards = (router) => {
    // 前置路由守卫
    router.beforeEach((to, from, next) => {
        console.log("进入跳转前路由",to,from)
        // 开启loading
        const Loading = window['$loading'] || null;
        Loading && Loading.start();
        // 判断路由是否需要缓存
        if (to.meta["cache"]) {
            // 用的时候创建实例，如果再函数顶上创建，会导致pinia还没有创建完毕，导致出错
            const myrouter = useMyRouter()
            myrouter.huancun(to)
        }
        // 执行跳转
        next()
        console.log("跳转结束",to,from)
        // 结束loading
        Loading && Loading.finish();
    })
}
